package org.nanotek.mq.receive;

import java.util.List;

import javax.jms.Message;

import org.nanotek.mq.Executor;
import org.nanotek.mq.receive.events.BaseMessageListener;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
//import org.springframework.jms.listener.DefaultMessageListenerContainer;

import sun.misc.Timeable;
import sun.misc.Timer;

public abstract class BaseReceiver implements ApplicationContextAware,Executor<BaseMessageListener,Message> , Timeable{

	private List<Message> message;

	public BaseReceiver(Long timeInterval) {
		(new Timer(this, timeInterval)).cont();
	}

	private static ClassPathXmlApplicationContext ctx;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ctx = new ClassPathXmlApplicationContext(new String[] {"activemq-config/base-activemq-context.xml" , "activemq-config/jms-exception-listener.xml"});
		BaseMessageListener listener = (BaseMessageListener) ctx.getBean("baseMessageListener");
		assert (listener !=null);
//		DefaultMessageListenerContainer container = (DefaultMessageListenerContainer) ctx.getBean("jmsContainer");
	}

	@Override
	public void processMessage(Message t1) {
			doSomething();
	}

	private void doSomething() {
	}

	public abstract void checkReceivedMessages();

	@Override
	public void tick(Timer arg0) {
		checkReceivedMessages();
	}


	public List<Message> getMessage() {
		return message;
	}


	public void setMessage(List<Message> message) {
		this.message = message;
	}
}
